package com.springboot.system.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.springboot.system.dao.JobDao;
import com.springboot.system.domain.auth.Job;
import com.springboot.common.exception.SystemException;
import com.springboot.common.utils.StringUtils;
import com.springboot.core.web.mvc.Page;

/**
 * 岗位业务层实现类
 * 
 * @ClassName: JobService
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author 252956
 * @date 2021年1月7日 上午9:53:14
 *
 */
@Service
public class JobService {
	@Autowired
	private JobDao jobDao;

	public Page<Job> page(Job job) {
		if (job == null) {
			throw new SystemException("参数不能为空");
		}
		return jobDao.selectPage(job);
	}

	public List<Job> selectAll() {
		return jobDao.selectAll();
	}

	public boolean add(Job job) {

		if (StringUtils.isBlank(job.getName())) {
			throw new SystemException("岗位名不能为空");
		}
		if (job.getStatus() == null) {
			throw new SystemException("状态不能为空");
		}
		jobDao.insert(job);
		return true;
	}

	public boolean update(Job job) {

		if (job.getId() == null) {
			throw new SystemException("id为空");
		}
		if (StringUtils.isBlank(job.getName())) {
			throw new SystemException("岗位名不能为空");
		}
		if (job.getStatus() == null) {
			throw new SystemException("状态不能为空");
		}
		jobDao.update(job);
		return true;

	}

	public boolean delete(Integer id) {
		if (id == null) {
			throw new SystemException("id不能为空");
		}
		jobDao.delete(new Job().setId(id));
		return true;
	}

	public Job select(Integer id) {
		if (id == null) {
			throw new SystemException("id不能为空");
		}
		return jobDao.selectOne(id);
	}

	public boolean updateStatus(Job job) {
		if (job.getId() == null) {
			throw new SystemException("id为空");
		}
		jobDao.updateStatus(job.getId(), job.getStatus());
		return true;
	}
}
